#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
using namespace std;

int tolls[1440];
struct Date{
	int day;
	int hour;
	int minute;
	Date(int day,int hour,int minute){
		this->day = day;
		this->hour = hour;
		this->minute = minute;
	}
	bool operator < (const Date & d) const{
		if( this->day != d.day ){
			return this->day < d.day;
		}else if( this->hour!= d.hour ){
			return this->hour < d.hour;
		}else return this->minute < d.minute;
	}
	int operator - (const Date & d) const {
		return (this->day-d.day)*1440 + (this->hour-d.hour)*60 + (this->minute-d.minute);
	}
};
struct Customer{
	string name;
	int month;
	Date date;
	string tag;
	Customer(string name,int month,Date d,string tag):date(d){
		this->name = name;
		this->month = month;
		this->tag = tag;
	}
	bool operator < (const Customer & c) const{
		if( this->name != c.name ){
			return this->name < c.name;
		}else return this->date < c.date;
	}
};
int bill(const Date & onDate,const int callTime){
	int begin = onDate.hour * 60 + onDate.minute, sum = 0;
	for(int i=0; i<callTime; i++ ){
		sum += tolls[(begin++)%1440];
	}
	return sum;
}
ostream & operator << (ostream & o,const Date & d){
	printf("%02d:%02d:%02d",d.day,d.hour,d.minute);
	return o;
}
double printOneLine(const Customer &oldR,const Customer &newR){
	int callTime = newR.date - oldR.date;
	cout << oldR.date << " " << newR.date << " " << callTime << " ";
	double res = bill(oldR.date,callTime)/100.0;
	printf("$%.2f\n",res);
	return res;
}
int main(){
	freopen("in.txt","r",stdin);
	for(int i=0; i<24; i++){
		int t;
		cin >> t;
		fill(tolls+60*i,tolls+60*i+60,t);
	}
	int n;
	cin >> n;
	vector<Customer> customers;
	for(int i=0; i<n; i++){
		string n,t;
		int m,d,h,mm;
		cin >> n;
		scanf("%d:%d:%d:%d",&m,&d,&h,&mm);
		cin >> t;
		customers.push_back(Customer(n,m,Date(d,h,mm),t));
	}
	sort(customers.begin(),customers.end());
	string oldName = customers[0].name;
	int oldMonth = customers[0].month;
	int flag = 0;//printf("%s %02d\n",oldName.c_str(),oldMonth);
	stack<Customer> oldOnLineRecord;
	if( customers[0].tag=="on-line" ) oldOnLineRecord.push(customers[0]);
	double total = 0;
	for(int i=1; i<customers.size(); i++){
		Customer newRecord = customers[i];
		if( newRecord.name==oldName ){
			if( newRecord.tag=="on-line"){
				oldOnLineRecord.push(newRecord);
			}else if( !oldOnLineRecord.empty()){
				if( flag == 0 ){
					printf("%s %02d\n",oldName.c_str(),oldMonth);
					flag = 2;
				}
				total += printOneLine(oldOnLineRecord.top(),newRecord);
				oldOnLineRecord.pop();
			}
		}else{
			if( flag==2 )printf("Total amount: $%.2f\n",total);
			total = 0;
			oldName = newRecord.name;
			oldMonth = newRecord.month;
			//oldOnLineRecord.clear();
			while( !oldOnLineRecord.empty()) oldOnLineRecord.pop();
			if( newRecord.tag=="on-line" ) oldOnLineRecord.push(newRecord);
			//printf("%s %02d\n",oldName.c_str(),oldMonth);
			flag = 0;
		}
	}
	if( flag==2 )printf("Total amount: $%.2f\n",total);
	return 0;
}
